<!--
 * @Description: 寝室视频列表 - 学生上传
 * @Author: liyujie
 * @Date: 2021/3/15
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/3/15
-->
<template>
    <div class="wrapper">
        <div class="content-wrapper">
            <!-- 筛选-->
            <div class="filter-view">
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        批次组名称
                    </p>
                    <el-input
                        placeholder="请输入批次组名称"
                        v-model="filterData.title"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        学校名称
                    </p>
                    <el-cascader
                        v-model="filterData.school_name"
                        placeholder="请选择学校"
                        :options="school_tree"
                        filterable
                        clearable
                        size="medium"
                        expand-trigger="click"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                        :props="{
                            label: 'name',
                            value: 'name',
                            children: 'children',
                            emitPath: false
                        }"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        批次组创建时间
                    </p>
                    <el-date-picker
                        v-model="dateTimeRange"
                        type="datetimerange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                        size="medium"
                        style="width: 400px"
                        value-format="timestamp"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        批次组创建人
                    </p>
                    <el-input
                        placeholder="请输入批次组创建人"
                        v-model="filterData.submit_admin_true_name"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="getTableData(1)"
                    >
                        查询
                    </el-button>
                    <!--<el-button
                        type="primary"
                        size="small"
                        @click="addSeries"
                    >
                        创建批次
                    </el-button>-->
                </div>
            </div>
            <!--筛选-->

            <!-- table -->
            <el-table
                :data="tableData"
                height="100%"
                style="width: 100%;"
                ref="tempLateName"
                class="data-table"
                v-loading="tableLoading"
            >
                <el-table-column
                    label="序号"
                    align="center"
                    width="80"
                    type="index"
                />
                <el-table-column
                    prop="title"
                    label="批次组名称"
                    show-overflow-tooltip
                    align="left"
                    min-width="110"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="school_name"
                    label="学校"
                    show-overflow-tooltip
                    align="center"
                    width="100"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    label="寝室性别"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        {{ scope.row.sex === 1 ? '男' : scope.row.sex === 2 ? '女' : '不限' }}
                    </template>
                </el-table-column>
                <el-table-column
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                    width="150"
                    :render-header="(h, title, content) => renderHeader(h, '有效数量/目标数量', '有效数量指的是运营审核通过的数量，目标数量指的是，运营创建批次的时候给用户定的目标数量。')"
                >
                    <template slot-scope="scope">
                        {{ scope.row.video_student_audit_pass_count }} / {{ scope.row.count }}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="video_student_audit_wait_count"
                    show-overflow-tooltip
                    align="center"
                    :render-header="(h, title, content) => renderHeader(h, '待审核数', '用户上传视频且提交了审核，总后台未进行审核的数量')"
                />
                <el-table-column
                    prop="video_student_audit_fail_count"
                    show-overflow-tooltip
                    align="center"
                    :render-header="(h, title, content) => renderHeader(h, '未通过数', '用户提交审核，未通过的数量')"
                />
                <el-table-column
                    prop="video_student_audit_submit_count"
                    show-overflow-tooltip
                    align="center"
                    :render-header="(h, title, content) => renderHeader(h, '提交总数', '用户上传视频且提交审核的数量之和')"
                />
                <el-table-column
                    prop="video_score"
                    show-overflow-tooltip
                    align="center"
                    :render-header="(h, title, content) => renderHeader(h, '总分数', '审核通过的视频分数之和，且是所有人的总分之和')"
                />
                <el-table-column
                    label="批次组创建时间"
                    align="center"
                    width="200"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        {{ scope.row.create_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="submit_admin_true_name"
                    label="批次组创建人"
                    align="center"
                    width="200"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    label="操作"
                    align="left"
                    width="180"
                >
                    <template slot-scope="scope">
                        <div class="option-btn-group">
                            <el-button
                                type="text"
                                size="medium"
                                @click="handleRoute('videoCompanyList', {no: scope.row.series_no})"
                            >
                                查看详情
                            </el-button>
                            <el-button
                                type="text"
                                size="medium"
                                @click="handleRoute('studentVideoDetail', {no: scope.row.series_no})"
                            >
                                查看视频
                            </el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <!-- /table -->

            <!-- /分页 -->
            <div class="pagination-wrapper clearfix">
                <el-pagination
                    layout="total, prev, pager, next, jumper"
                    background
                    :current-page.sync="page.now_page"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />
            </div>
        </div>
        <student-series-dialog
            ref="studentSeriesDialog"
            @update="getTableData(1)"
        />
    </div>
</template>

<script>
import { back } from '@/mixin/back';
import StudentSeriesDialog from "@/components/dorm/student-series-dialog";

export default {
    name: 'StudentVideoList',
    mixins: [back],
    components: {StudentSeriesDialog},
    data() {
        return {
            filterData: {
                type: 2,
                // 批次组名
                title: '',
                // 学校名称
                school_name: '',
                sex: 99,
                // 创建时间
                start_submit_time: '',
                end_submit_time: '',
                // 创建人
                submit_admin_true_name: '',
                is_audit: 0
            },
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            dateTimeRange: [],
            // 性别
            sexList: [
                {label: '全部', value: 99},
                {label: '不限', value: 0},
                {label: '男', value: 1},
                {label: '女', value: 2},
            ],
            // 视频批次列表
            seriesList: [],
            school_tree: [],
        };
    },
    computed: {},
    watch: {
        dateTimeRange(value) {
            this.filterData.start_submit_time = value ? value[0] / 1000 : '';
            this.filterData.end_submit_time = value ? value[1] / 1000 : '';
            this.getTableData(1);
        },
    },

    mounted() {
        this.authResult = this.$route.meta.authResult;
        this.getSchoolTree();
        this.getTableData();
    },

    methods: {

        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {
            this.tableLoading = true;
            let params = { ...this.filterData };

            params.page_id = page || this.page.now_page;
            this.$post('/student/room_series%5Cget_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                    this.page = res.data.page;
                }
                this.tableLoading = false;
            });
        },

        /**
         * @description 获取省/市/学校三级联动
         */
        getSchoolTree () {
            this.$post('/student/local_info%5Cschool_tree',{},resp => {
                if (resp.code === 1) {
                    this.school_tree = resp.data.tree;
                }
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },

        /**
         * 自定义表格标题hover提示
         */
        renderHeader(h,title, content){
            return h('span', {}, [
                h('span', {}, title),
                h('el-popover', { props: { placement: 'top-start', width: '200', trigger: 'hover', content: content }}, [
                    h('i', { slot: 'reference', class:'el-icon-question', style: 'color:#666'}, '')
                ])
            ]);
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * 新建批次
         */
        addSeries() {
            if(!this.authResult.auth_add_series) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }
            this.$refs.studentSeriesDialog.show();
        },

        /**
         * 编辑批次
         * @param row
         * @returns {boolean}
         */
        handleEdit(row) {
            if(!this.authResult.auth_edit_series) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }
            this.$refs.studentSeriesDialog.show('edit', row);
        },
    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;
    flex: 1;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        padding: 0 24px;
        background: #fff;
        box-sizing: border-box;

        /*header*/

        .header {
            box-sizing: border-box;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid #F0F2F5;

            .header-title {
                color: #333333;
                font-size: 20px;
                height: 20px;
                font-weight: 500;
                position: relative;
                margin-left: 12px;
                margin-bottom: 24px;

                &::before {
                    content: '';
                    position: absolute;
                    left: -8px;
                    top: -1px;
                    width: 3px;
                    height: 20px;
                    background: #1890FF;
                }
            }
        }

        /*筛选*/

        .filter-view {
            margin-top: 12px;
            box-sizing: border-box;
            display: flex;
            align-items: center;
            flex-wrap: wrap;

            .header-new-box {
                display: flex;
                align-items: center;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                white-space: nowrap;
                margin-right: 24px;
                margin-bottom: 12px;

                &-title {
                    margin-right: 16px;
                    white-space: nowrap;
                }
            }
        }

        // 表格
        .data-table {
            ::-webkit-scrollbar {
                width: 6px;
                height: 6px;
            }
            // 操作按钮
            .option-btn-group {
                .el-button {
                    margin-left: 0;
                    margin-right: 10px;
                }
            }
            .title-wrap {
                display: flex;
                align-items: center;
                cursor: pointer;
                .series-title {
                    max-width: 200px;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    overflow: hidden;
                }
                .title-spliter {
                    width: 1px;
                    height: 12px;
                    background: rgba(235, 235, 235, 1);
                    margin: 0 10px;
                }
                .title-sort {
                    font-size: 14px;
                    line-height: 1;
                    color: #ccc;
                    &:hover {
                        color: #20a0ff;
                    }
                }
            }
        }
        /* 分页 */

        .pagination-wrapper {
            padding-top: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
}
</style>

